Remove xm commands block-refresh and vbd-refresh, as these are unsupported.
authoremellor@ewan <emellor@ewan>
Thu, 6 Oct 2005 18:41:29 +0000 (19:41 +0100)
committeremellor@ewan <emellor@ewan>
Thu, 6 Oct 2005 18:41:29 +0000 (19:41 +0100)
Allow xm block-detach to take a device name as well as a device ID.  This
closes bug #285 and fixes xm-test's 01_block-destroy_btblock_pos.py and
02_block-destroy_rtblock_pos.py.

Rename and reconnect XendDomainInfo.configureDevice to reconfigureDevice.
There is nothing using this at the moment, mind you.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xend/XendClient.py
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xend/server/DevController.py
tools/python/xen/xend/server/SrvDomain.py
tools/python/xen/xend/server/blkif.py
tools/python/xen/xm/main.py

index 0919ae6da6421f153d7b4b85bb7e2febd4cdc5c8..5f198ac9f7b6b8626e66fc00d9535ca6423a5c63 100644 (file)
@@ -306,22 +306,22 @@ class Xend:
                              {'op'      : 'device_create',
                               'config'  : fileof(config) })
 
-    def xend_domain_device_refresh(self, id, type, idx):
+    def xend_domain_device_refresh(self, id, type, dev):
         return self.xendPost(self.domainurl(id),
                              {'op'      : 'device_refresh',
                               'type'    : type,
-                              'idx'     : idx })
+                              'dev'     : dev })
 
-    def xend_domain_device_destroy(self, id, type, idx):
+    def xend_domain_device_destroy(self, id, type, dev):
         return self.xendPost(self.domainurl(id),
                              {'op'      : 'device_destroy',
                               'type'    : type,
-                              'idx'     : idx })
+                              'dev'     : dev })
 
-    def xend_domain_device_configure(self, id, config, idx):
+    def xend_domain_device_configure(self, id, config, dev):
         return self.xendPost(self.domainurl(id),
                              {'op'      : 'device_configure',
-                              'idx'     : idx,
+                              'dev'     : dev,
                               'config'  : fileof(config) })
 
     def xend_vnets(self):
index 9fcc28d385f6ddf8e4408d945e4416b67245d240..56e967dfb76240e2ea31f88efc9da716d97dbdf2 100644 (file)
@@ -492,13 +492,6 @@ class XendDomain:
                              devconfig, devid)
 
     
-    def domain_device_refresh(self, domid, devtype, devid):
-        """Refresh a device."""
-        return self.callInfo(domid,
-                             XendDomainInfo.XendDomainInfo.device_refresh,
-                             devtype, devid)
-
-
     def domain_device_destroy(self, domid, devtype, devid):
         """Destroy a device."""
         return self.callInfo(domid,
index 19814c6bdc57c4694cb1e9354ded9fb2a2be11a1..659256dd17e720d370d451f76dd7825a481231aa 100644 (file)
@@ -876,25 +876,29 @@ class XendDomainInfo:
     __repr__ = __str__
 
 
+    ## private:
+
     def createDevice(self, deviceClass, devconfig):
         return self.getDeviceController(deviceClass).createDevice(devconfig)
 
 
-    def configureDevice(self, deviceClass, devid, devconfig):
-        return self.getDeviceController(deviceClass).configureDevice(
+    def reconfigureDevice(self, deviceClass, devid, devconfig):
+        return self.getDeviceController(deviceClass).reconfigureDevice(
             devid, devconfig)
 
 
+    ## public:
+
     def destroyDevice(self, deviceClass, devid):
         return self.getDeviceController(deviceClass).destroyDevice(devid)
 
 
+    ## private:
+
     def getDeviceSxprs(self, deviceClass):
         return self.getDeviceController(deviceClass).sxprs()
 
 
-    ## private:
-
     def getDeviceConfigurations(self, deviceClass):
         return self.getDeviceController(deviceClass).configurations()
 
@@ -1234,7 +1238,7 @@ class XendDomainInfo:
         @param devid:      device id
         """
         deviceClass = sxp.name(dev_config)
-        self.configureDevice(deviceClass, devid, dev_config)
+        self.reconfigureDevice(deviceClass, devid, dev_config)
 
 
     ## private:
index 47b850fc61ae53b2954d82c8f6df5e558ae83c58..1b94f145256aa62f75a80c3778de6b81c3d15b52 100644 (file)
@@ -86,8 +86,7 @@ class DevController:
            
 
     def configurations(self):
-        return map(lambda x: self.configuration(int(x)),
-                   xstransact.List(self.frontendRoot()))
+        return map(self.configuration, self.deviceIDs())
 
 
     def configuration(self, devid):
@@ -176,7 +175,14 @@ class DevController:
         return xstransact.Read(backpath, *args)
 
 
-    ## private:
+    def deviceIDs(self):
+        """@return The IDs of each of the devices currently configured for
+        this instance's deviceClass.
+        """
+        return map(int, xstransact.List(self.frontendRoot()))
+
+
+## private:
 
     def writeDetails(self, config, devid, backDetails, frontDetails):
         """Write the details in the store to trigger creation of a device.
index 6b9cb7b202ad533e4fac13e7d6c13c9f398490d4..8c70bfe27d3f7206e4db0237848acaac5c9894bf 100644 (file)
@@ -156,19 +156,11 @@ class SrvDomain(SrvDir):
         val = fn(req.args, {'dom': self.dom.domid})
         return val
 
-    def op_device_refresh(self, op, req):
-        fn = FormFn(self.xd.domain_device_refresh,
-                    [['dom',  'int'],
-                     ['type', 'str'],
-                     ['idx',  'int']])
-        val = fn(req.args, {'dom': self.dom.domid})
-        return val
-
     def op_device_destroy(self, op, req):
         fn = FormFn(self.xd.domain_device_destroy,
                     [['dom',  'int'],
                      ['type', 'str'],
-                     ['idx',  'int']])
+                     ['dev',  'str']])
         val = fn(req.args, {'dom': self.dom.domid})
         return val
                 
@@ -176,7 +168,7 @@ class SrvDomain(SrvDir):
         fn = FormFn(self.xd.domain_device_configure,
                     [['dom',    'int'],
                      ['config', 'sxpr'],
-                     ['idx',    'int']])
+                     ['dev',    'str']])
         val = fn(req.args, {'dom': self.dom.domid})
         return val
 
index 34bc4278c6435d471dc44624358c74fd66b8644e..3782fa5a0072541fd53483623865d800342ccfbd 100644 (file)
@@ -23,7 +23,7 @@ import string
 from xen.util import blkif
 from xen.xend import sxp
 
-from xen.xend.server.DevController import DevController
+from DevController import DevController
 
 
 class BlkifController(DevController):
@@ -79,3 +79,23 @@ class BlkifController(DevController):
             result.append(['mode', 'w'])
 
         return result
+
+
+    def destroyDevice(self, devid):
+        """@see DevController.destroyDevice"""
+
+        # If we are given a device name, then look up the device ID from it,
+        # and destroy that ID instead.  If what we are given is an integer,
+        # then assume it's a device ID and pass it straight through to our
+        # superclass's method.
+
+        try:
+            DevController.destroyDevice(self, int(devid))
+        except ValueError:
+            for i in self.deviceIDs():
+                if self.readBackend(i, 'dev') == devid:
+                    DevController.destroyDevice(self, i)
+                    return
+            # Try this, but it's almost certainly going to throw VmError,
+            # since we can't find the device.
+            DevController.destroyDevice(self, int(devid))
index df458c5d88d3d956c96dc0aec4fe9a5995b91789..8433d819daddd847542ea02d6a229485755bbc8c 100644 (file)
@@ -106,9 +106,10 @@ xm full list of subcommands:
   Virtual Device Commands:
     block-attach  <DomId> <BackDev> <FrontDev> <Mode> [BackDomId]
         Create a new virtual block device 
-    block-detach  <DomId> <DevId>  Destroy a domain's virtual block device
+    block-detach  <DomId> <DevId>  Destroy a domain's virtual block device,
+                                   where <DevId> may either be the device ID
+                                   or the device name as mounted in the guest.
     block-list    <DomId>          List virtual block devices for a domain
-    block-refresh <DomId> <DevId>  Refresh a virtual block device for a domain
     network-limit   <DomId> <Vif> <Credit> <Period>
         Limit the transmission rate of a virtual network interface
     network-list    <DomId>        List virtual network interfaces for a domain
@@ -522,25 +523,11 @@ def xm_block_attach(args):
     from xen.xend.XendClient import server
     server.xend_domain_device_create(dom, vbd)
 
-def xm_block_refresh(args):
-    arg_check(args,2,"block-refresh")
-
-    dom = args[0]
-    dev = args[1]
-
-    from xen.xend.XendClient import server
-    server.xend_domain_device_refresh(dom, 'vbd', dev)
-
 def xm_block_detach(args):
     arg_check(args,2,"block-detach")
 
     dom = args[0]
-
-    try:
-        dev = int(args[1])
-    except ValueError, e:
-        err("Invalid device id: %s" % args[1])
-        sys.exit(1)
+    dev = args[1]
 
     from xen.xend.XendClient import server
     server.xend_domain_device_destroy(dom, 'vbd', dev)
@@ -622,7 +609,6 @@ commands = {
     "block-attach": xm_block_attach,
     "block-detach": xm_block_detach,
     "block-list": xm_block_list,
-    "block-refresh": xm_block_refresh,
     # network
     "network-limit": xm_network_limit,
     "network-list": xm_network_list,
@@ -651,7 +637,6 @@ aliases = {
     "vbd-create": "block-create",
     "vbd-destroy": "block-destroy",
     "vbd-list": "block-list",
-    "vbd-refresh": "block-refresh",
     }
 
 help = {